package com.yueya.business.bed.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.yueya.common.util.UUIDGenerator;

@SuppressWarnings("serial")
public class Floor extends Model<Floor> {
	
	
	private List<Room> rooms;
	public static Floor dao = new Floor();
	
	
   
	
	public boolean save(Floor dao){
		dao.set("floor_id", UUIDGenerator.getUUID());
		return dao.save();
	}
	
	public boolean update(Floor dao){
		return dao.update();
	}
	
	public boolean remove(Floor dao){
		dao.set("del_flag","1");
		return dao.update();
	}
	
	//栋编号
		public static  String no() {
			String number ="";
			String tag ="F";
			long count = 1 + Db
					.queryLong("SELECT COUNT(floor_id)  FROM jg_floor ");
			if (0 < count) {
				if (10 > count)
					number = tag + "000" + count;
				else if (100 > count)
					number = tag + "00" + count;
				else if (1000 > count)
					number = tag + "0" + count;
				else
					number = tag + count;
			}
		   
			return number;
		}
	
		
		 public List<Floor> getList(String  house_id) {
			 return Floor.dao.find("select * from jg_floor where house_id=? order by floor_no",house_id);
		 }
		 
		 
		 public List<Map<String, Object>> getAllList(String house_id) {
			   List<Map<String, Object>>  result = new ArrayList<Map<String, Object>>();
			    List<Floor>  list = getList(house_id);
			    Iterator<Floor> it = list.iterator();
			    while(it.hasNext()) {
			    	Map<String, Object> map =new HashMap<String, Object>();
			    	Floor floor = it.next();
			    	map.put("id", floor.getStr("floor_id"));
			    	map.put("floorName", floor.getStr("floor_name"));
			    	List<Map<String, Object>> listfloor =	Room.dao.getAllList(floor.getStr("floor_id"));
			    	map.put("rooms", listfloor);
			        result.add(map);
			     }	
			 return result;
		 }

		public List<Room> getRooms() {
			return rooms;
		}

		public void setRooms(List<Room> rooms) {
			this.rooms = rooms;
		}
		
	
}
